// 如果临时身份证没有跳转到登录页面
//加的验证1
let res = localStorage.getItem("token");
if (res == null) {
    location.href = '/login.html'
}


// 获取个人信息 URL接口
function getlist() {
    $.ajax({
        url: "/my/userinfo",
        // 设置请求头：
        headers: {
            Authorization: localStorage.getItem("token")
        },
        success: function (res) {
            if (res.status == 0) {
                let name = res.data.nickname || res.data.username
                let pic = res.data.user_pic;
                $(".username").text(name)
                if (pic != null) {
                    $(".layui-nav-img").show().attr("src", pic)
                    $(".avatar").hide()
                } else {
                    let first = name.slice(0, 1).toLocaleUpperCase()
                    $(".layui-nav-img").hide()
                    $(".avatar").show().text(first).css("display", "inline-block")
                }

            }
        },

    })
}
getlist()
//点击退出到登录页面
let layer;
layui.use(['layer'], function () {
    layer = layui.layer;
    $("#logout").on("click", function () {
        layer.confirm("确定要退出?", function (index) {
            layer.close(index)
            //加的验证3退出时,清除token
            localStorage.removeItem("token")
            location.href = "/login.html"
        })
    })
})